package cn.zymall.goods.service.impl;

import cn.zymall.common.model.Collect;
import cn.zymall.common.model.HomeBillboards;
import cn.zymall.common.model.Spu;
import cn.zymall.common.model.UserCollect;
import cn.zymall.common.utils.response.HttpResult;
import cn.zymall.goods.mapper.SpuMapper;
import cn.zymall.goods.service.SpuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lxh
 * @Description TODO
 * @date 2020/8/21 16:15
 * @Classname SpuServiceIpl
 **/
@Service
public class SpuServiceImpl extends ServiceImpl<SpuMapper, Spu> implements SpuService {

    @Autowired
    private SpuMapper spuMapper;


    @Override
    public List<Spu> findAll() {
        return spuMapper.findAll();
    }

    @Override
    public Spu add(Spu spu) {
        spuMapper.add(spu);
        return spu;
    }

    @Override
    public void addSpuDetail(Spu spu) {
        spuMapper.addSpuDetail(spu);
    }

    @Override
    public void amend(Spu spu) {
        spuMapper.amend(spu);
    }

    @Override
    public List<Spu> composeFind(Spu spu) {
        return spuMapper.composeFind(spu);
    }

    @Override
    public void examineStatus(Spu spu) {
        spuMapper.examineStatus(spu);
    }

    @Override
    public void deleteExamineStatus(Integer id) {
        spuMapper.deleteExamineStatus(id);
    }

    @Override
    public void submitExamine(Spu spu) {
        spuMapper.submitExamine(spu);
    }

    @Override
    public void updateSpuRecommend(Spu spu) {
        spuMapper.updateSpuRecommend(spu);
    }

    @Override
    public List<Spu> getCollectSpu(UserCollect userCollect) {
        return spuMapper.getCollectSpu(userCollect);
    }

    @Override
    public HttpResult removeCollectSpu(List<Collect> list) {
        try {
            spuMapper.removeCollectSpu(list);
            return new HttpResult().success("删除完成");
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult().success("删除失败，请重试");
        }
    }

    @Override
    public Spu findByIdSpu(Integer id) {
        return spuMapper.findByIdSpu(id);
    }

    @Override
    public PageInfo<Spu> findAllSpu(Integer page, Integer rows) {
        PageHelper.startPage(page,rows);
        final List<Spu> allSpu = spuMapper.findAllSpu();
        PageInfo<Spu> pageaa = new PageInfo<>(allSpu);
       return pageaa;
    }


}
